﻿<script language=JavaScript src='../inv/scripts/innovaeditor.js'></script>
<?
$path = "../upload";
$pathdb = "../upload";
$hunga=$_REQUEST['page'];
	$pagehung = $_REQUEST['page'];
if (isset($_POST['butSaveLoai'])) {
	$code=$_POST['txtCode'];
	$name=$_POST['txtName'];
	$namecn=$_POST['txtNamecn'];
	$price=$_POST['txtPrice'];	
	$donvi=$_POST['txtDonVi'];
	$desc=$_POST['txtDesc'];
	$shortdesc=$_POST['txtShortDesc'];
	$categories_id=$_POST['ddCat'];
	$provider_id=$_POST['ddProvider'];


	$err="";

	if($name =="") $err .=  "B&#7841;n ch&#432;a nh&#7853;p tên s&#7843;n ph&#7849;m<br>";
	
//	$ret=CheckUpload($_FILES["txtImage"],".jpg;.gif;.png;.jpeg;",500*1024,($_POST['id']!=''?0:1));
//	if ($ret) $err.="T&#7853;p tin không &#273;úng &#273;&#7883;nh d&#7841;ng ho&#7863;c kích th&#432;&#7899;c quá l&#7899;n<br>";
	
//	$ret=CheckUpload($_FILES["txtImageLarge"],".jpg;.gif;.png;.png;.jpeg;",500*1024,0);
//	if ($ret) $err.="T&#7853;p tin không &#273;úng &#273;&#7883;nh d&#7841;ng ho&#7863;c kích th&#432;&#7899;c quá l&#7899;n<br>";
/*
-if($price =="") $err .=  "B&#7841;n ch&#432;a nh&#7853;p giá<br>";
	else if (!is_numeric($price)) $err.="Giá s&#7843;n ph&#7849;m không h&#7907;p l&#7879;";
*/
	if ($err=='')
	{ $psinfo=GetCategoryInfo($categories_id);
			$psid=$psinfo['parent_id'];
			$language=$psinfo['language'];
		if (!empty($_POST['id'])) {
			$oldid = $_POST['id'];
			$sql = "update products set products_code='".$code."',products_name='".$name."',products_price='".$price."',products_donvi='".$donvi."',products_shortdescription='".addslashes($shortdesc)."',products_description='".addslashes($desc)."',products_include='".$namecn."',categories_id='".$categories_id."',providers_id='".$psid."', language='".$language."' where products_id='".$oldid."'";
		}else {
			$sql = "insert into products (products_code,products_name,products_image,products_image_large,products_price,products_donvi,products_shortdescription,products_description,products_include,categories_id,providers_id, products_date_added,language) values ('".$code."','".$name."','','','".$price."','".$donvi."','".addslashes($shortdesc)."','".addslashes($desc)."','".$namecn."','".$categories_id."','".$psid."',SYSDATE(),'".$language."')";
		}
		
		if (mysql_query($sql,$con)) {
			if(empty($_POST['id'])) $oldid = mysql_insert_id();

			$sqlUpdateField = "";
if ($_POST['chkClear']=='')
			{
			$ext=GetFileExtention($_FILES['txtImage']['name']);
			if (MakeUpload($_FILES['txtImage'],"$path/product_s$oldid$ext"))
			{
				@chmod("$path/product_s$oldid$ext", 0777);
				$sqlUpdateField = " products_image='$pathdb/product_s$oldid$ext' ";
			}
	}
			else 
			{
				// delete old image
				//$news= GetNewsInfo($oldid);
				//if (@file_exists($news['news_image'])) @unlink($news['news_image']);
				$sqlUpdateField = " products_image='' ";
			}
			
			$ext=GetFileExtention($_FILES['txtImageLarge']['name']);
			if (MakeUpload($_FILES['txtImageLarge'],"$path/product_l$oldid$ext"))
			{
				@chmod("$path/product_l$oldid$ext", 0777);
				if($sqlUpdateField  != "") $sqlUpdateField .= ",";
				$sqlUpdateField .= " products_image_large='$pathdb/product_l$oldid$ext' ";
			}
			
			if($sqlUpdateField)
			{
				$sqlUpdate = "update products set $sqlUpdateField where products_id='".$oldid."'";
				mysql_query($sqlUpdate,$con);
			}
		}	
		else {
			$err =  "<p align=center class='err'>Không th&#7875; c&#7853;p nh&#7853;t</p>";
		}
  	}
  	if ($err=='') echo '<script>window.location="index.php?act=product&cat='.$_REQUEST['cat'].'&page='.$_REQUEST['page'].'&code=1"</script>';
  	else echo "<p align=center class='err'>".$err."</p>";
} 
?>

<?
	if (isset($_GET['id'])) {
		$oldid=$_GET['id'];
		$page = $_GET['page'];
		$sql = "select * from products where products_id='".$oldid."'";
		if ($result = mysql_query($sql,$con)) {
			$row=mysql_fetch_array($result);
			$code=$row['products_code'];
			$name=$row['products_name'];
			$namecn=$row['products_include'];
			$image=$row['products_image'];
			$categories_id = $row['categories_id'];
			$imagelarge=$row['products_image_large'];
			$price=$row['products_price'];
			$donvi=$row['products_donvi'];
			$shortdesc=$row['products_shortdescription'];
			$desc=$row['products_description'];
			
			$provider_id=$row['providers_id'];
			$psid=$row['providers_id'];
		}
	}
?>

<form method="post" name="FormLoaiSP" enctype="multipart/form-data" action="index.php">
<input type="hidden" name="act" value="product_m">
<input type="hidden" name="page" value="<? echo $_REQUEST['page']; ?>">
<input type="hidden" name="id" value="<? echo $_REQUEST['id']; ?>">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#0069A8" width="100%" id="AutoNumber1">
  <tr>
    <td width="45%" class="title" align="center" height="20">S&#7917;a / C&#7853;p nh&#7853;t : S&#7843;n ph&#7849;m</td>
  </tr>
  <tr>
    <td width="45%">
    <table border="0" cellpadding="2" bordercolor="#111111" width="100%" id="AutoNumber2" cellspacing="0">
<?    
if ($image!='')
{
	echo '<tr><td colspan="3" align="center"><img border="0" src="'.$image.'"></td></tr>';
}
?>		
   <tr>
        <td width="25%" class="smallfont">
        <p align="right">Mã</td>
        <td width="2%" class="smallfont" align="center">&nbsp;        </td>
        <td width="73%" class="smallfont">
		<INPUT value="<?echo $code; ?>" TYPE="text" NAME="txtCode" CLASS=textbox size="34"></td>
      </tr> 
      <tr>
        <td width="25%" class="smallfont">
        <p align="right">Tên s&#7843;n ph&#7849;m Tiếng  anh </td>
        <td width="2%" class="smallfont" align="center">
        <font color="#FF0000">*</font></td>
        <td width="73%" class="smallfont">
		<INPUT value="<? echo $name; ?>" TYPE="text" NAME="txtName" CLASS=textbox size="34"></td>
      </tr>
      <tr>
        <td width="25%" class="smallfont">
        <p align="right">Tên s&#7843;n ph&#7849;m Tiếng Việt</td>
        <td width="2%" class="smallfont" align="center">
        <font color="#FF0000">*</font></td>
        <td width="73%" class="smallfont">
		<INPUT value="<? echo $namecn; ?>" TYPE="text" NAME="txtNamecn" CLASS=textbox size="34"></td>
      </tr>
      <tr>
        <td width="25%" class="smallfont">
        <p align="right">Hình &#7843;nh (kích th&#432;&#7899;c nh&#7887;)</td>
        <td width="2%" class="smallfont" align="center">
        <font color="#FF0000">*</font></td>
        <td width="73%" class="smallfont">
		<INPUT TYPE="file" NAME="txtImage" CLASS=textbox size="34"><input type="checkbox" name="chkClear" value="ON">
		Xóa 
		b&#7887; hình<span class="style1">(Cập nhật hình cho mục Specials)</span></td>
      </tr>
      <tr>
        <td width="25%" class="smallfont">
        <p align="right">Hình &#7843;nh (kích th&#432;&#7899;c l&#7899;n)</td>
        <td width="2%" class="smallfont" align="center">&nbsp;        </td>
        <td width="73%" class="smallfont">
		<INPUT TYPE="file" NAME="txtImageLarge" CLASS=textbox size="34"></td>
      </tr>
     
	  <tr>	  
        <td width="25%" class="smallfont" align="right">Giá  </td>
        <td width="2%" class="smallfont" align="right">&nbsp;  </td>
        <td width="73%" class="smallfont">
			<table>
				<tr>
					<td>
						<INPUT value="<? echo $price; ?>" TYPE="text" NAME="txtPrice" CLASS=textbox size="20"></td>
					<td width="40" class="smallfont">&nbsp;&nbsp; &#272;&#417;n v&#7883;</td>
					<td width="38%" class="smallfont">
						<select size="1" name="txtDonVi">
				<?
						$dv=GetListDonVi();
						foreach ($dv as $dv1)
						{
							if ($dv1[0]==$donvi)
								echo "<option value=".$dv1[0]." selected>".$dv1[1]."</option>";
							else
								echo "<option value=".$dv1[0].">".$dv1[1]."</option>";
						}
				?>		
						</select>
					</td>
		  		</tr>
		  	</table>
		</td>
	</tr>

      <tr>
        <td width="25%" class="smallfont" align="right">
        Thông tin chi ti&#7871;t Tiếng việt </td>
        <td width="2%" class="smallfont" align="center">&nbsp;        </td>
        <td width="73%" class="smallfont">
			<textarea id="txtDesc" name="txtDesc" rows=4 cols=30><? echo $desc; ?></textarea>
			<script> //STEP 2: Replace the textarea (txtContent)
			var oEdit1 = new InnovaEditor("oEdit1");
			oEdit1.arrStyle=[["BODY",false,"","font-family:Tahoma,Arial,Helvetica;font-size:10pt"]];
			oEdit1.width="100%";//You can also use %, for example: oEdit1.width="100%"
			oEdit1.height=350;		
			oEdit1.cmdAssetManager = "modalDialogShow('/inv/assetmanager/assetmanager.php',640,465)"; //Command to open the Asset Manager add-on.
			oEdit1.REPLACE("txtDesc");//Specify the id of the textarea here
			</script>		
		</td>
      </tr>
	   <tr>
        <td width="17%" class="smallfont" align="right"> Thông tin chi ti&#7871;t Tiếng anh</td>
        <td width="1%" class="smallfont" align="center"></td>
        <td width="80%" class="smallfont"> 
		
			<textarea id="txtShortDesc" name="txtShortDesc" rows=4 cols=30><? echo $shortdesc; ?></textarea>
			
				<script> //STEP 2: Replace the textarea (txtContent)
			var oEdit1shortdesc = new InnovaEditor("oEdit1shortdesc");
			oEdit1shortdesc.arrStyle=[["BODY",false,"","font-family:Tahoma,Arial,Helvetica;font-size:10pt"]];
			oEdit1shortdesc.width="100%";//You can also use %, for example: oEdit1.width="100%"
			oEdit1shortdesc.height=350;		
			oEdit1shortdesc.cmdAssetManager = "modalDialogShow('/inv/assetmanager/assetmanager.php',640,465)"; //Command to open the Asset Manager add-on.
			oEdit1shortdesc.REPLACE("txtShortDesc");//Specify the id of the textarea here
			</script></td>	
	  </tr> 
      <tr>
        <td width="25%" class="smallfont" align="right">
        Thu&#7897;c danh m&#7909;c</td>
        <td width="2%" class="smallfont" align="center">&nbsp;        </td>
        <td width="73%" class="smallfont">
		<select size="1" name="ddCat">
<?
		$cats=GetListCategory();
		foreach ($cats as $cat)
		{
			if ($cat[0]==$categories_id)
				echo "<option value=".$cat[0]." selected>".$cat[1]."</option>";
			else
				echo "<option value=".$cat[0].">".$cat[1]."</option>";
		}
?>		
		</select></td>
      </tr>
<!--      <tr>
        <td width="21%" class="smallfont" align="right">
        Thu&#7897;c nhà cung c&#7845;p</td>
        <td width="2%" class="smallfont" align="center">&nbsp;        </td>
        <td width="77%" class="smallfont">
		<select size="1" name="ddProvider">
<?
		echo "<option value='0'>[Không ch&#7885;n]</option>";
		$providers=GetListProvider();
		foreach ($providers as $provider)
		{
			if ($provider[0]==$provider_id)
				echo "<option value=".$provider[0]." selected>".$provider[1]."</option>";
			else
				echo "<option value=".$provider[0].">".$provider[1]."</option>";
		}
?>		
		</select></td>
      </tr>-->

      <tr>
        <td width="25%" class="smallfont">
		<p align="right">
		<INPUT TYPE="submit" NAME="butSaveLoai" VALUE="C&#7853;p nh&#7853;t" CLASS=button>&nbsp;</td>
        <td width="2%" class="smallfont" align="center">&nbsp;		</td>
        <td width="73%" class="smallfont"><p align="left">&nbsp;<INPUT TYPE="reset" CLASS=button value="Nh&#7853;p l&#7841;i"></td>
      </tr>
    </table>
    </td>
  </tr>
  </table>
</form>